# Contributor: techknowlogick <techknowlogick@gitea.com>
# Maintainer: techknowlogick <techknowlogick@gitea.com>
pkgname=ytt
pkgver=0.46.2
pkgrel=0
pkgdesc="YAML templating tool that works on YAML structure instead of text"
url="https://carvel.dev/ytt/"
arch="all !armhf !armv7 !x86"
license="Apache-2.0"
makedepends="go"
options="chmod-clean net"
source="$pkgname-$pkgver.tar.gz::https://github.com/carvel-dev/ytt/archive/v$pkgver.tar.gz
	0001-e2e-tests.patch"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local ldflags="-X github.com/vmware-tanzu/carvel-ytt/pkg/version.Version=$pkgver"
	export GOPATH="$srcdir"
	export CGO_ENABLED=0
	rm -f website/generated.go

	go fmt ./cmd/... ./pkg/...
	go mod vendor
	go mod tidy

	rm -f pkg/website/generated.go
	go build -trimpath -ldflags="$ldflags" -o ytt ./cmd/ytt/...
	./ytt version

	(
		# Use newly built binary to template all website assets
		# into a single Go file
		cd pkg/website
		./../../ytt \
			-f . \
			-f ../../examples/playground/basics \
			-f ../../examples/playground/overlays \
			-f ../../examples/playground/getting-started \
			--file-mark 'alt-example**/*:type=data' \
			--file-mark 'example**/*:type=data' \
			--file-mark 'generated.go.txt:exclusive-for-output=true' \
			--dangerous-emptied-output-directory ../../tmp/
	)
	mv tmp/generated.go.txt pkg/website/generated.go

	# Rebuild ytt with website assets
	rm -f ./ytt
	go build -trimpath -ldflags="$ldflags" -o ytt ./cmd/ytt/...
}

check() {
	# disable specific shellcheck test as wordsplitting is wanted
	# shellcheck disable=SC2046
	go test -v $(go list ./...|grep -v yaml.v2) "$@"
	./ytt version
}

package() {
	install -D -m 755 $pkgname "$pkgdir"/usr/bin/$pkgname
}

sha512sums="
0a8da5991bf68c032e85253092500ffbb86f73dcb51b84c9b9d791b5c5e8d1e8adabe17d4446e434fb9dd28142ab0977ec8343e3ca452d8616ce87d180da615e  ytt-0.46.2.tar.gz
7e90b64b9f5ed789002f30e1dfbe0c0a8176f1e619c14aa1e9d541359f2f24ff17165785c09b2f7b7bcc21082b568527506c20b6a33987a03f9c88a0c418cfaf  0001-e2e-tests.patch
"
